package com.endi.sap.controller;

import com.endi.sap.dingding.CreateDingClient;
import com.endi.sap.httpUtils.SAPHttpRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
public class MyController {

    @Autowired
    private CreateDingClient createDingClient;

    @Autowired
    private SAPHttpRequest request;

    @GetMapping("/public/hello")
    public String publicHello() {

        String url = "https://cpi-avyvidrh.it-cpi010-rt.cpi.cn40.apps.platform.sapcloud.cn/http/DingTalk/SD/CustomerMaterialChange";
        String jsonBody = "{\n" +
                "\"SalesOrganization\":\"1000\",\n" +
                "\"DistributionChannel\":\"10\",\n" +
                "\"Customer\":\"1000012\",\n" +
                "\"Material\":\"101010003\",\n" +
                "\"MaterialByCustomer\":\"2134521312TEST\",\n" +
                "\"MaterialDescriptionByCustomer\":\"test111\"\n" +
                "}\n";
        request.post(url,null,jsonBody);
        return "Hello, this is a public endpoint!";
    }

    @PostMapping("/public/nihao")
    public Map<String, Object> nihao(@RequestBody Map<String,Object> map) {
        //获取Map中的access_token
        String accessToken = (String) map.get("access_token");
        System.out.println(accessToken);
        System.out.println((String) map.get("formInsId"));
        Map<String, Object> result = new HashMap<>();
        result.put("name","jack");
        System.out.println("");
        return map;
    }


    @GetMapping("/private/hello")
    public String privateHello() {
        return "Hello, this is a private endpoint!";
    }

    @GetMapping("/native/hello")
    public String natives() {
        return "OK";
    }
}

